package com.huawei.hwCloudJs.service.http;

import android.content.Context;
import android.util.Log;
import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import com.huawei.hms.framework.network.util.HttpUtils;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

public final class a {
    public static final String a = "POST";
    public static final int b = 1;
    public static final int c = 2;
    public static final int d = 3;
    public static final int e = 10;
    private static final String f = "BaseRequest";

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private java.lang.String a(java.io.InputStream r6) {
        /*
        r5 = this;
        if (r6 != 0) goto L_0x0005;
    L_0x0002:
        r0 = "";
    L_0x0004:
        return r0;
    L_0x0005:
        r0 = "";
        r1 = new java.io.ByteArrayOutputStream;
        r1.<init>();
        r2 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
        r2 = new byte[r2];
    L_0x0010:
        r3 = r6.read(r2);	 Catch:{ IOException -> 0x001c }
        r4 = -1;
        if (r3 == r4) goto L_0x0031;
    L_0x0017:
        r4 = 0;
        r1.write(r2, r4, r3);	 Catch:{ IOException -> 0x001c }
        goto L_0x0010;
    L_0x001c:
        r2 = move-exception;
        r2 = "BaseRequest";
        r3 = "readStream IOException:";
        android.util.Log.e(r2, r3);	 Catch:{ all -> 0x0044 }
        r1.close();	 Catch:{ IOException -> 0x0028 }
        goto L_0x0004;
    L_0x0028:
        r1 = move-exception;
        r1 = "BaseRequest";
        r2 = "outStream IOException:";
        android.util.Log.e(r1, r2);
        goto L_0x0004;
    L_0x0031:
        r2 = "UTF-8";
        r0 = r1.toString(r2);	 Catch:{ IOException -> 0x001c }
        r1.close();	 Catch:{ IOException -> 0x003b }
        goto L_0x0004;
    L_0x003b:
        r1 = move-exception;
        r1 = "BaseRequest";
        r2 = "outStream IOException:";
        android.util.Log.e(r1, r2);
        goto L_0x0004;
    L_0x0044:
        r0 = move-exception;
        r1.close();	 Catch:{ IOException -> 0x0049 }
    L_0x0048:
        throw r0;
    L_0x0049:
        r1 = move-exception;
        r1 = "BaseRequest";
        r2 = "outStream IOException:";
        android.util.Log.e(r1, r2);
        goto L_0x0048;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwCloudJs.service.http.a.a(java.io.InputStream):java.lang.String");
    }

    private HttpURLConnection a(String str, String str2, String str3, Context context) {
        HttpURLConnection httpURLConnection;
        try {
            URL url = new URL(str);
            if (str.startsWith(HttpUtils.HTTP_PREFIX)) {
                httpURLConnection = (HttpURLConnection) url.openConnection();
            } else {
                HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
                c.a(httpsURLConnection, context);
            }
            try {
                httpURLConnection.setRequestMethod(str2);
                httpURLConnection.setDoInput(true);
                if (str2.equalsIgnoreCase("POST")) {
                    httpURLConnection.setDoOutput(true);
                }
                httpURLConnection.setUseCaches(false);
                httpURLConnection.setConnectTimeout(60000);
                httpURLConnection.setReadTimeout(60000);
                httpURLConnection.setRequestProperty("Connection", "keep-alive");
                httpURLConnection.setRequestProperty("Charset", "UTF-8");
                if (str3 != null) {
                    httpURLConnection.setRequestProperty(HttpContants.KEY_CONTENT_TYPE, str3);
                }
            } catch (MalformedURLException e) {
                Log.e(f, "getURLConnection MalformedURLException");
                return httpURLConnection;
            } catch (IOException e2) {
                Log.e(f, "getURLConnection IOException");
                return httpURLConnection;
            }
        } catch (MalformedURLException e3) {
            httpURLConnection = null;
            Log.e(f, "getURLConnection MalformedURLException");
            return httpURLConnection;
        } catch (IOException e4) {
            httpURLConnection = null;
            Log.e(f, "getURLConnection IOException");
            return httpURLConnection;
        }
        return httpURLConnection;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public <T extends com.huawei.hwCloudJs.service.http.a.d> T a(com.huawei.hwCloudJs.service.http.a.c<T> r13, android.content.Context r14) {
        /*
        r12 = this;
        r0 = 0;
        r2 = r13.a();
        r1 = r13.g();
        r3 = r13.j();
        r4 = r13.i();	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        r4 = r12.a(r2, r3, r4, r14);	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        if (r4 != 0) goto L_0x0024;
    L_0x0017:
        r2 = 10;
        r1.c(r2);	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        com.huawei.hwCloudJs.d.f.a(r0);
        com.huawei.hwCloudJs.d.f.a(r0);
        r0 = r1;
    L_0x0023:
        return r0;
    L_0x0024:
        r4.connect();	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        r3 = r13.h();	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        r2 = android.text.TextUtils.isEmpty(r3);	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        if (r2 != 0) goto L_0x00f5;
    L_0x0031:
        r2 = new java.io.DataOutputStream;	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        r5 = r4.getOutputStream();	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        r2.<init>(r5);	 Catch:{ IOException -> 0x00f2, RuntimeException -> 0x00b7, all -> 0x00cf }
        r5 = "UTF-8";
        r3 = r3.getBytes(r5);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r2.write(r3);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r2.flush();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
    L_0x0046:
        r3 = r4.getResponseCode();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r5 = 200; // 0xc8 float:2.8E-43 double:9.9E-322;
        if (r3 != r5) goto L_0x0084;
    L_0x004e:
        r0 = r4.getInputStream();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r5 = r12.a(r0);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r6 = 1;
        r1.c(r6);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r1.b(r3);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r6 = new java.util.HashMap;	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r6.<init>();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r7 = r1.c();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r3 = r7.length;	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        if (r3 <= 0) goto L_0x0079;
    L_0x0069:
        r8 = r7.length;	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r3 = 0;
    L_0x006b:
        if (r3 >= r8) goto L_0x0079;
    L_0x006d:
        r9 = r7[r3];	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r10 = r4.getHeaderField(r9);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r6.put(r9, r10);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
        r3 = r3 + 1;
        goto L_0x006b;
    L_0x0079:
        r1.a(r5, r6);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00ec }
    L_0x007c:
        com.huawei.hwCloudJs.d.f.a(r0);
        com.huawei.hwCloudJs.d.f.a(r2);
    L_0x0082:
        r0 = r1;
        goto L_0x0023;
    L_0x0084:
        r4 = "BaseRequest";
        r5 = new java.lang.StringBuilder;	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r5.<init>();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r6 = "geturl failed";
        r5 = r5.append(r6);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r5 = r5.append(r3);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r5 = r5.toString();	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        android.util.Log.e(r4, r5);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r4 = 2;
        r1.c(r4);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        r1.b(r3);	 Catch:{ IOException -> 0x00a4, RuntimeException -> 0x00e6, all -> 0x00da }
        goto L_0x007c;
    L_0x00a4:
        r3 = move-exception;
    L_0x00a5:
        r3 = 3;
        r1.c(r3);	 Catch:{ all -> 0x00df }
        r3 = "BaseRequest";
        r4 = "geturl failed IOException";
        android.util.Log.e(r3, r4);	 Catch:{ all -> 0x00df }
        com.huawei.hwCloudJs.d.f.a(r0);
        com.huawei.hwCloudJs.d.f.a(r2);
        goto L_0x0082;
    L_0x00b7:
        r2 = move-exception;
        r3 = r0;
        r11 = r0;
        r0 = r2;
        r2 = r11;
    L_0x00bc:
        r4 = 10;
        r1.c(r4);	 Catch:{ all -> 0x00e4 }
        r4 = "BaseRequest";
        r5 = "doRequest RuntimeException";
        android.util.Log.e(r4, r5, r0);	 Catch:{ all -> 0x00e4 }
        com.huawei.hwCloudJs.d.f.a(r2);
        com.huawei.hwCloudJs.d.f.a(r3);
        goto L_0x0082;
    L_0x00cf:
        r1 = move-exception;
        r2 = r0;
        r3 = r0;
        r0 = r1;
    L_0x00d3:
        com.huawei.hwCloudJs.d.f.a(r2);
        com.huawei.hwCloudJs.d.f.a(r3);
        throw r0;
    L_0x00da:
        r1 = move-exception;
        r3 = r2;
        r2 = r0;
        r0 = r1;
        goto L_0x00d3;
    L_0x00df:
        r1 = move-exception;
        r3 = r2;
        r2 = r0;
        r0 = r1;
        goto L_0x00d3;
    L_0x00e4:
        r0 = move-exception;
        goto L_0x00d3;
    L_0x00e6:
        r3 = move-exception;
        r11 = r3;
        r3 = r2;
        r2 = r0;
        r0 = r11;
        goto L_0x00bc;
    L_0x00ec:
        r3 = move-exception;
        r11 = r3;
        r3 = r2;
        r2 = r0;
        r0 = r11;
        goto L_0x00bc;
    L_0x00f2:
        r2 = move-exception;
        r2 = r0;
        goto L_0x00a5;
    L_0x00f5:
        r2 = r0;
        goto L_0x0046;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwCloudJs.service.http.a.a(com.huawei.hwCloudJs.service.http.a.c, android.content.Context):T");
    }
}
